from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-03-05 14:06:56.218778
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 05, Mar, 2021
Time: 14:07:01
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.6053
Nobs: 221.000 HQIC: -47.4304
Log likelihood: 2570.53 FPE: 1.44152e-21
AIC: -47.9891 Det(Omega_mle): 9.67929e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.465144 0.134585 3.456 0.001
L1.Burgenland 0.065718 0.068573 0.958 0.338
L1.Kärnten -0.211217 0.058461 -3.613 0.000
L1.Niederösterreich 0.169496 0.155966 1.087 0.277
L1.Oberösterreich 0.240361 0.139274 1.726 0.084
L1.Salzburg 0.211805 0.073779 2.871 0.004
L1.Steiermark 0.107151 0.099114 1.081 0.280
L1.Tirol 0.125449 0.066976 1.873 0.061
L1.Vorarlberg -0.010622 0.061040 -0.174 0.862
L1.Wien -0.148433 0.129969 -1.142 0.253
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.477552 0.161079 2.965 0.003
L1.Burgenland 0.011189 0.082072 0.136 0.892
L1.Kärnten 0.350236 0.069969 5.006 0.000
L1.Niederösterreich 0.090528 0.186668 0.485 0.628
L1.Oberösterreich -0.114293 0.166690 -0.686 0.493
L1.Salzburg 0.197411 0.088302 2.236 0.025
L1.Steiermark 0.198493 0.118625 1.673 0.094
L1.Tirol 0.142726 0.080160 1.781 0.075
L1.Vorarlberg 0.156136 0.073056 2.137 0.033
L1.Wien -0.496854 0.155553 -3.194 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.310116 0.062494 4.962 0.000
L1.Burgenland 0.094843 0.031842 2.979 0.003
L1.Kärnten -0.018635 0.027146 -0.686 0.492
L1.Niederösterreich 0.082864 0.072422 1.144 0.253
L1.Oberösterreich 0.298213 0.064671 4.611 0.000
L1.Salzburg 0.009280 0.034259 0.271 0.786
L1.Steiermark -0.004550 0.046023 -0.099 0.921
L1.Tirol 0.072652 0.031100 2.336 0.019
L1.Vorarlberg 0.099120 0.028344 3.497 0.000
L1.Wien 0.062714 0.060350 1.039 0.299
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.222827 0.067431 3.305 0.001
L1.Burgenland 0.000344 0.034357 0.010 0.992
L1.Kärnten 0.018599 0.029291 0.635 0.525
L1.Niederösterreich 0.039102 0.078143 0.500 0.617
L1.Oberösterreich 0.387698 0.069780 5.556 0.000
L1.Salzburg 0.086257 0.036965 2.333 0.020
L1.Steiermark 0.175235 0.049659 3.529 0.000
L1.Tirol 0.043577 0.033557 1.299 0.194
L1.Vorarlberg 0.083555 0.030583 2.732 0.006
L1.Wien -0.057848 0.065118 -0.888 0.374
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.515047 0.133887 3.847 0.000
L1.Burgenland 0.068628 0.068217 1.006 0.314
L1.Kärnten 0.012178 0.058158 0.209 0.834
L1.Niederösterreich -0.011407 0.155157 -0.074 0.941
L1.Oberösterreich 0.133386 0.138551 0.963 0.336
L1.Salzburg 0.063422 0.073396 0.864 0.388
L1.Steiermark 0.101412 0.098600 1.029 0.304
L1.Tirol 0.218400 0.066628 3.278 0.001
L1.Vorarlberg 0.027215 0.060723 0.448 0.654
L1.Wien -0.117625 0.129294 -0.910 0.363
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.192207 0.097310 1.975 0.048
L1.Burgenland -0.021915 0.049581 -0.442 0.658
L1.Kärnten -0.008955 0.042270 -0.212 0.832
L1.Niederösterreich 0.047713 0.112769 0.423 0.672
L1.Oberösterreich 0.410946 0.100700 4.081 0.000
L1.Salzburg -0.006620 0.053345 -0.124 0.901
L1.Steiermark -0.016313 0.071663 -0.228 0.820
L1.Tirol 0.175520 0.048426 3.624 0.000
L1.Vorarlberg 0.043587 0.044134 0.988 0.323
L1.Wien 0.190549 0.093972 2.028 0.043
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.237112 0.124728 1.901 0.057
L1.Burgenland 0.033318 0.063551 0.524 0.600
L1.Kärnten -0.036946 0.054180 -0.682 0.495
L1.Niederösterreich -0.032182 0.144543 -0.223 0.824
L1.Oberösterreich -0.076901 0.129074 -0.596 0.551
L1.Salzburg 0.067421 0.068375 0.986 0.324
L1.Steiermark 0.403499 0.091855 4.393 0.000
L1.Tirol 0.454016 0.062071 7.315 0.000
L1.Vorarlberg 0.157348 0.056570 2.781 0.005
L1.Wien -0.203867 0.120450 -1.693 0.091
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126123 0.148892 0.847 0.397
L1.Burgenland 0.023069 0.075863 0.304 0.761
L1.Kärnten -0.071057 0.064676 -1.099 0.272
L1.Niederösterreich 0.191387 0.172546 1.109 0.267
L1.Oberösterreich -0.016199 0.154079 -0.105 0.916
L1.Salzburg 0.254737 0.081622 3.121 0.002
L1.Steiermark 0.141517 0.109650 1.291 0.197
L1.Tirol 0.049427 0.074096 0.667 0.505
L1.Vorarlberg 0.064680 0.067529 0.958 0.338
L1.Wien 0.239713 0.143784 1.667 0.095
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.574532 0.080012 7.181 0.000
L1.Burgenland -0.035375 0.040767 -0.868 0.386
L1.Kärnten -0.017127 0.034756 -0.493 0.622
L1.Niederösterreich -0.002046 0.092723 -0.022 0.982
L1.Oberösterreich 0.309927 0.082799 3.743 0.000
L1.Salzburg 0.019607 0.043862 0.447 0.655
L1.Steiermark -0.010529 0.058924 -0.179 0.858
L1.Tirol 0.078948 0.039818 1.983 0.047
L1.Vorarlberg 0.120363 0.036289 3.317 0.001
L1.Wien -0.030686 0.077267 -0.397 0.691
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.130452 0.038330 0.188070 0.242196 0.055833 0.131679 -0.040171 0.166652
Kärnten 0.130452 1.000000 0.004645 0.195783 0.164327 -0.114276 0.147412 0.011761 0.314585
Niederösterreich 0.038330 0.004645 1.000000 0.274587 0.062411 0.249410 0.166598 0.048638 0.344525
Oberösterreich 0.188070 0.195783 0.274587 1.000000 0.296243 0.277695 0.095000 0.075251 0.133003
Salzburg 0.242196 0.164327 0.062411 0.296243 1.000000 0.128127 0.046373 0.086922 -0.001617
Steiermark 0.055833 -0.114276 0.249410 0.277695 0.128127 1.000000 0.123431 0.118614 -0.110419
Tirol 0.131679 0.147412 0.166598 0.095000 0.046373 0.123431 1.000000 0.178921 0.159182
Vorarlberg -0.040171 0.011761 0.048638 0.075251 0.086922 0.118614 0.178921 1.000000 0.025693
Wien 0.166652 0.314585 0.344525 0.133003 -0.001617 -0.110419 0.159182 0.025693 1.000000